package IoCz;

import Book.Book;
import Book.BookList;

public class IoDelete implements IoCz{
    @Override
    public void ioCz(BookList bookList) {
        System.out.println("====删除图书====");
        System.out.println("请选择要删除图书的名字");
        String name = scanner.nextLine();
        System.out.println("==================");
        for (int i = 0; i < bookList.booksize; i++) {
             Book book = bookList.books[i];
             if(name.equals(book.getName())){
                 for (int j = i; j < bookList.booksize-1; j++) {
                     bookList.setpos(j,bookList.books[j+1]);
                     /*book.setName(bookList.books[j+1].getName());
                     book.setAuthor(bookList.books[j+1].getAuthor());
                     book.setPrice(bookList.books[j+1].getPrice());
                     book.setBoo(bookList.books[j+1].getBoo());*/
                 }
                 /*bookList.books[bookList.booksize-1].setName(null);
                 bookList.books[bookList.booksize-1].setAuthor(null);
                 bookList.books[bookList.booksize-1].setPrice(0);
                 bookList.books[bookList.booksize-1].setBoo(false);*/
                 bookList.setpos(bookList.booksize-1, null);
                 System.out.println("已删除");
                 bookList.booksize--;
                 IoShow ioShow = new IoShow();
                 ioShow.ioCz(bookList);
                 return;
             }
        }
        System.out.println("没有此书");
    }
}
